<template>
	<view>
		<view v-if="orders">
			<!-- 通知 -->
			<view v-if="orders.old_orders&&orders.old_orders.length>0">
				<u-notice-bar mode="horizontal" :is-circular="false" :autoplay="false" :volume-icon="false"
					v-if="orders.old_orders.find((item)=>item.generate_type==3)!=undefined"
					:list="['此订单提前还车，请留意']"></u-notice-bar>
				<u-notice-bar mode="horizontal" :is-circular="false" :autoplay="false" :volume-icon="false"
					v-if="orders.old_orders.find((item)=>item.generate_type==4)!=undefined"
					:list="['此订单超时，请留意']"></u-notice-bar>
				<u-notice-bar mode="horizontal" :is-circular="false" :autoplay="false" :volume-icon="false"
					v-if="orders.old_orders.find((item)=>item.generate_type==5)!=undefined"
					:list="['此订单已续租，请留意']"></u-notice-bar>
			</view>
			<view v-if="!orders.orderDriver">
				<u-notice-bar mode="horizontal" :is-circular="false" :autoplay="false" :volume-icon="false"
					@click="toPage('addDriver')" :list="['提醒：该订单未添加驾驶员，请添加驾驶员']"></u-notice-bar>
			</view>
			<!-- 通知 -->
			<view v-if="!orders.custom">
				<u-notice-bar mode="horizontal" :is-circular="false" :autoplay="false" :volume-icon="false"
					:list="['提醒：订单尚未添加客户，请添加客户']"></u-notice-bar>
			</view>
			<!-- 通知 -->
			<view v-if="orders.carValidateList.find((item)=>item.validate_object==1)==undefined">
				<u-notice-bar mode="horizontal" :is-circular="false" :autoplay="false" :volume-icon="false" @click="carValidatePage()"
					:list="['订单尚未验车，请进行验车']"></u-notice-bar>
			</view>
			<view>
				<u-cell-group>
					<u-cell-item :arrow="false">
						<view slot="title" style="">
							<text v-if="orders.orders_source_id==1">后台录入</text>
							<text v-if="orders.orders_source_id==2">系统商城</text>
							<text v-if="orders.orders_source_id==3">哈罗</text>
							<text v-if="orders.orders_source_id==4">飞猪</text>
							<text v-if="orders.orders_source_id==5">携程</text>
							<text v-if="orders.orders_source_id==6">滴滴打车</text>
							<text v-if="orders.orders_source_id==7">第三方推荐</text>
							<text style="margin-left: 30rpx;">{{orders.orders_num}}</text>
						</view>
						<view slot="right-icon" style="color: #2979ff;" @click="coppy(orders.orders_num)">
							<text>复制</text>
							<u-icon name="file-text"></u-icon>
						</view>
					</u-cell-item>
				</u-cell-group>
			</view>
			<!-- 订单状态 -->
			<view
				style="display: grid;grid-template-columns: repeat(2,1fr);grid-gap: 20rpx;background-color: white;padding: 30rpx;align-items: center;">
				<view>
					<text>订单状态：</text>
					<text v-if="orders.state_id==1">预定</text>
					<text v-if="orders.state_id==2">待出车</text>
					<text v-if="orders.state_id==3">已出车</text>
					<text v-if="orders.state_id==4">已还车</text>
					<text v-if="orders.state_id==5">已结算</text>
					<text v-if="orders.state_id==6">结束v</text>
				</view>
				<view>
					<text>订单金额：</text>
					<text>{{orders.total_amount}}元</text>
				</view>
				<view>
					<text>待支付金额：</text>
					<text>{{orders.unpay_amount}}元</text>
				</view>
				<view>
					<text>押金金额：</text>
					<text>{{orders.unpay_amount}}元</text>
				</view>


			</view>
			<!-- 车辆信息 -->
			<u-cell-group title="车辆信息">
				<u-cell-item :title="orders.myType?orders.myType.cx:'[无法显示]'" :arrow="false">
					<view slot="right-icon">
						<u-tag :text="orders.car_num" type="primary" />
					</view>
				</u-cell-item>
				<u-cell-item title="车型信息" :value="orders.car_type_name" :arrow="false"></u-cell-item>
			</u-cell-group>
			<!-- 客户信息 -->
			<u-cell-group title="客户信息">
				<u-cell-item title="客户姓名" :value="orders.custom_name?orders.custom_name:orders.appt_name" :arrow="false">
					<view slot="right-icon">
						<u-tag style="margin-left: 20rpx;" v-if="orders.custom_type==1" text="个人" type="primary"
							mode="light" />
						<u-tag style="margin-left: 20rpx;" v-if="orders.custom_type==2" text="单位" type="warning"
							mode="light" />
					</view>
				</u-cell-item>
				<u-cell-item title="联系电话" :arrow="false">
					<view slot="right-icon" style="color: #2979ff;font-weight: bold;" @click="call(orders.custom_tel?orders.custom_tel:orders.appt_tel)" >
						<text>{{orders.custom_tel?orders.custom_tel:orders.appt_tel}}</text>
						<u-icon style="margin-left: 10rpx;border: solid  #2979ff 2px;padding: 5rpx;border-radius: 40rpx;"
							name="phone-fill"></u-icon>
					</view>
				</u-cell-item>
				<u-cell-item v-if="orders.custom_type==2" :title="orders.unit_name?orders.unit_name:'[无法显示]'"
					:value="orders.unit_dept_name?orders.unit_dept_name:'[无法显示]'" :arrow="false"></u-cell-item>
			</u-cell-group>
			<!-- 租赁信息 -->
			<u-cell-group title="租赁信息">
				<view style="padding-bottom: 150rpx;">
					<u-cell-item value="取车"
						:label="orders.takeReturn3?orders.takeReturn3.location_address:orders.takeReturn1.location_address"
						:arrow="false">
						<view slot="title">
							<text>{{orders.take_date}}</text>
							<u-tag style="margin:0 20rpx;" v-if="orders.orders_is_night==2" text="夜间" size="mini"
								type="warning" mode="dark" />
							<u-tag style="margin-left: 20rpx;" v-if="orders.orders_is_night==2" text="急单" size="mini"
								type="error" mode="dark" />
						</view>
					</u-cell-item>
					<u-cell-item :title="orders.return_date" value="还车"
						:label="orders.takeReturn4?orders.takeReturn4.location_name:orders.takeReturn2.location_name"
						:arrow="false"></u-cell-item>
					<u-cell-item title="租赁时长" :value="strDateToTime2(orders.take_date,orders.return_date)"
						:arrow="false"></u-cell-item>
					<u-cell-item title="送车司机" :value="orders.employe_name" :arrow="false"></u-cell-item>
					</u-cell-item>
				</view>
			</u-cell-group>



			<view
				style="position: fixed;bottom: 0;width: 100%; height: 150rpx;background-color: white;padding: 30rpx;box-shadow: -3px -3px 10px #c8c9cc;z-index: 999;">
				<view style="display: flex;justify-content: space-around;">
					<view>
						<u-action-sheet :list="actionSheetList" v-model="showMore"
							@click="clickActionSheet"></u-action-sheet>
						<u-button size="mini" type="primary" @click="showMore=true">
							<text>更多</text>
							<u-icon name="arrow-down"></u-icon>
						</u-button>
					</view>
					<view>
						<u-button size="mini" type="primary" @click="toPage('ordersPayment')">明细</u-button>
					</view>
					<view>
						<u-button size="mini" type="primary" @click="toPage('payAmount')">支付</u-button>
					</view>
					<view v-if="parseFloat(orders.expense_amount).toFixed(2)>0.00">
						<u-button size="mini" type="primary" @click="toPage('backAmount')">退款</u-button>
					</view>
					<view>
						<u-button size="mini" type="primary" @click="toPage('orderDeposit')">押金</u-button>
					</view>
					<view v-if="orders.state_id<3">
						<u-button size="mini" type="warning"
							v-if="orders.carValidateList.find((item)=>item.validate_object==1)==undefined"
							@click="carValidatePage('carValidate')">验车</u-button>
						<u-button size="mini" type="primary"
							v-if="orders.carValidateList.find((item)=>item.validate_object==1)!=undefined"
							@click="show=true">出车</u-button>
					</view>
				</view>
			</view>
		</view>
		<u-modal v-model="show" @confirm="chuche" title="确定出车吗？" :show-cancel-button="true">
			<view class="slot-content" style="padding: 30rpx;">
				<view>
					<text>车牌号：</text>
					<text>{{orders.car_num}}</text>
				</view>
				<view>
					<text>客户姓名：</text>
					<text>{{orders.custom_name}}</text>
				</view>
				<view>
					<text>出车时间：</text>
					<text>{{orders.take_date}}</text>
				</view>
				<view style="color: #909399;margin-top: 10rpx;font-size: 12px;">
					<u-icon name="question-circle"></u-icon>
					<text>若出车时间与实际出车时间不一致，请先修改后出车。</text>
				</view>
			</view>
		</u-modal>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	import dateUtils from '../../utils/dateUtils';
	export default {
		data() {
			return {
				actionSheetList: [{
					text: '订单备注',
					value: 'ordresRemarks'
				}, {
					text: '换车',
					value: 'replaceCar'
				}, {
					text: '换司机',
					value: 'replaceEmploye'
				}, {
					text: '添加/修改驾驶员',
					value: 'addDriver'
				}, {
					text: '添加附件',
					value: 'addDoc'
				}],
				orders: null,
				showMore: false,
				show: false
			}
		},
		onLoad(options) {
			if (options.data) {
				this.orders = JSON.parse(decodeURIComponent(options.data));
				console.log(this.orders);
			}
			if (uni.getStorageSync('permissions')) {
				this.permissions = JSON.parse(uni.getStorageSync('permissions'));
				if (this.permissions.includes('orders:orders:updateTakeReturn')&&this.orders.orders_source_id!=1) {
					this.actionSheetList.push({
						text: '修改取还车信息',
						value: 'updateTakeReturn'
					})
				}
				if (this.permissions.includes('orders:orders:updateLocalTakeReturn')&&this.orders.orders_source_id==1) {
					this.actionSheetList.push({
						text: '修改取还车信息',
						value: 'updateTakeReturn'
					})
				}
			}
		},
		mounted() {
			var that = this;
			uni.$on('getOrdersInfo', function(data) {
				console.log("监听到了，啦啦啦");
				that.getOrderInfo();
			})
		},
		methods: {
			chuche() {
				var that = this;
				var form = this.orders.takeReturn1;
				that.$http.post('/orders/chuche', form, (res) => {
					if (res.data.success) {
						that.$refs.uToast.show({
							title: '出车成功',
							type: "success"
						});
						uni.$emit("getOrdersInfo", that.data);
					} else {
						that.refs.myModal.show('请求失败', res.data.result.message);
					}
				});
			},
			clickActionSheet(index) {
				var page = this.actionSheetList[index].value;
				console.log(page);
				uni.navigateTo({
					url: '/pages/' + page + '/' + page + '?data=' + encodeURIComponent(JSON.stringify(this.orders))
				})
			},
			call(phoneNumber) {
				uni.makePhoneCall({
					phoneNumber: phoneNumber
				})
			},
			strDateToTime2(take_date, return_date) {
				return dateUtils.strDateToTime2(take_date, return_date);
			},
			coppy(text) {
				uni.setClipboardData({
					data: text,
					success: function() {
						uni.showToast({
							title: '复制成功',
							icon: 'success',
							duration: 1000
						});
					}
				});
			},
			toPage(e) {
				uni.navigateTo({
					url: '/pages/' + e + '/' + e + '?data=' + encodeURIComponent(JSON.stringify(this.orders))
				})
			},
			carValidatePage() {
				var list= this.orders.carValidateList.filter(item=>item.validate_object==1);
				uni.navigateTo({
					url: '/pages/carValidate/carValidate?orders_id=' + this.orders.orders_id + '&object=1&list='+JSON.stringify(list)
				})
			},
			getOrderInfo() {
				var that = this;
				that.$http.get('/orders/queryById?orders_id=' + this.orders.orders_id, {}, (res) => {
					if (res.data.success) {
						that.orders = res.data.result;
					} else {
						that.refs.myModal.show('请求失败', res.data.result.message);
					}
				});
			},
			click() {
				console.log("33333");
			}
		}
	}
</script>

<style>

</style>